<?php

	class Page{
		private $total;
		private $num;
		private $limit_start;
		private $pageNum;
		private $page;
		private $pageList = 2;
		private $listNum;

		
		public function __construct($total,$num){
			$this->total = $total;
			$this->num = $num;
			$this->listNum = $listNum;
			$this->limit_start = $this->limit_start();
			$this->pageNum = $this->pageNum();
			$this->page = $this->page();
			$this->pageList = $this->pageList();
		}
		
		//获取当前页码，并将其赋值给limit_start;
		function pageNum(){
			$pageNum = ceil($this->total/$this->num);
			return $pageNum;
		}
		function page(){
			$url = $_SERVER['REQUEST_URI'].(strpos($_SERVER['REQUEST_URI'],'?') ? ''  :"?");
			$parse = parse_url($url);
			if(isset($parse["query"])){
				parse_str($parse["query"],$url);
				$page = $url[page];
			}
			return $page;
		}
		function limit_start(){
			$url = $_SERVER['REQUEST_URI'].(strpos($_SERVER['REQUEST_URI'],'?') ? ''  :"?");
			$parse = parse_url($url);
			if(isset($parse["query"])){
				parse_str($parse["query"],$url);
				$limit_start = $url[page];
				if($limit_start > 1){
					$limit_start = ($limit_start-1)*$this->num;
				}else{
					$limit_start = 0;
				}
				return $limit_start = "limit ".$limit_start.",".$this->num;
			}
		}
		function pageList(){
			$linkpage = "";
			$totalpage = $this->pageNum();
			$inum = floor($totalpage/2);
			
			for($i=$inum;$i>=1;$i--){
				$page = $this->page-$i;
				if($page < 1){
					continue;
				}
				$linkpage .= "&nbsp;<a href='?page=$page'>{$page}</a>&nbsp;";
				

			}
			$linkpage .= "&nbsp;{$this->page}&nbsp;";

			for($i=1;$i<$inum;$i++){
				$page = $this->page+$i;
				if($page <= $totalpage){
					$linkpage .= "&nbsp;<a href='?page=$page'>{$page}</a>&nbsp;";
				}else{
					break;
				}
			}
			return $linkpage;
		}
		function pageFirst(){
			$html .= "&nbsp;<a href='?page=1'>首页</a>&nbsp;";
			return $html;
		}
		function pageTotal(){
			$html .= "&nbsp;共{$this->pageNum()}页&nbsp;";
			return $html;
		}
		function pageLast(){
			$html .= "&nbsp;<a href='?page=$this->pageNum'>尾页</a>&nbsp;";
			return $html;
		}
		function pagePre(){
			$pagePre = $this->page-1;
			if($pagePre >= 1){
				$html .= "&nbsp;<a href='?page=$pagePre'>上一页</a>";
			}
			return $html;
		}
		function pageNext(){
			$pageNext = $this->page+1;
			if($pageNext <= $this->pageNum()){
				$html .= "&nbsp;<a href='?page=$pageNext'>下一页</a>";			
			}
			return $html;
		}
		
		function fpage(){
			$html .= $this->pagefirst();
			$html .= $this->pagePre();
			$html .= $this->pageList();
			$html .= $this->pageNext();
			$html .= $this->pageLast();
			$html .= $this->pageTotal();
			
			return $html;
		}
	}

?>